// components/like/index.js
Component({
  /**
   * 组件的属性列表
   * 可开发出来的数据
   */
  properties: {
    like:{
      type:Boolean
    },
    count:{
      type:Number
    }, 
    readOnly: {
      type: Boolean
    },
  },

  /**
   * 组件的初始数据
   * 封闭的数据
   */
  data: {
    yesPng:'images/like.png',
    noPng:'images/like-init.png'

  },

  /**
   * 组件的方法列表
   */
  methods: {
    onLike:function(event){
      if(this.properties.readOnly){
        return
      }
      let like = this.properties.like
      let count=this.properties.count
      count = like ? count-1 : count+1
      this.setData({
        count: count,
        like: !like
      })
      //获取点赞状态
      let behavior = this.properties.like?'like':'cancel'
      //激活自定义事件
      this.triggerEvent('like',{
        behavior:behavior
      })
    }
  }
})
